/**
 * 工具函数
 */
//字体图标
require("../../fonts/iconfont.css")

//接口地址
let BASE_URL = "http://139.9.177.51:8099"

/* 验证手机号码 */
function isPhone(num) {
    return /^1[3-9]\d{9}$/.test(num)
}
/* 验证密码 */
function isPassword(pwd) {
    return /^[a-zA-Z0-9_]{6,12}$/.test(pwd);
}

//封装弹框提示
function toast(type = "icon-test", msg = "操作成功!", time = 2000) {
    // 1.创建一个标签作为弹框盒子
    let div = document.createElement("div");
    //  2 设置类名
    div.className = "toast-container";
    //  3 设置内容
    div.innerHTML = `
      <span class="iconfont icon-${type}"></span>
      <p class="mt20">${msg}</p>
   `
    //  4 添加到页面
    document.body.appendChild(div);
    //  5 指定的时间后要删除
    window.setTimeout(function () {
        div.remove();
    }, time)
}

/* 封装底部导航栏 tabbar */
function addTabbar(currentPage) {
    //1 创建标签
    let div = document.createElement("div");
    //2 设置类名
    div.className = "tabbar-container";
    //3 设置内容
    div.innerHTML = `
    <a  href="./home.html" class="tabbar-item  ${currentPage === "home" ? "active" : ""}">
       <span class="iconfont icon-shouye"></span>
       <p>首页</p>
    </a>
    <a href="./course.html" class="tabbar-item  ${currentPage === "course" ? "active" : ""}">
       <span class="iconfont icon-iconfont-yundongjiankang"></span>
       <p>运动</p>
    </a>
    <a href="./mine.html" class="tabbar-item ${currentPage === "mine" ? "active" : ""}">
       <span class="iconfont icon-wode2"></span>
       <p>我的</p>
    </a>
    `;
    //4 添加到页面
    document.querySelector("#footer").appendChild(div);
}

/*把方法挂载到window对象身上 (相当于暴露)*/
window.$utils = {
    isPhone: isPhone,
    isPassword: isPassword,
    BASE_URL: BASE_URL,
    toast: toast,
    addTabbar:addTabbar
} 